/*
 * Use or Copy is free, but retain author declaration.
 */
package pyip.lib.mixtool.simplehttpclient;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

/**
 * @author yepeng
 * @date 2015年3月9日
 */
public abstract class Request {

    public static final String METHOD_NAME_POST = "POST";
    public static final String METHOD_NAME_GET = "GET";

    private String url;
    private Map<String, String[]> params;
    private Map<String, String> headers;
    private RequestConfig config;

    /**
     * @param url 不能为空
     */
    public Request(String url) {
        if (StringUtils.isBlank(url)) {
            throw new IllegalArgumentException("参数url不能为空");
        }
        this.url = url;
    }

    public abstract String getMethod();

    public String[] addParameter(String key, String[] values) {
        if (params == null) {
            params = new HashMap<String, String[]>();
        }
        return params.put(key, values);
    }

    public String addHeader(String key, String value) {
        if (headers == null) {
            headers = new HashMap<String, String>();
        }
        return headers.put(key, value);
    }

    public String getUrl() {
        return url;
    }

    public Map<String, String[]> getParams() {
        return params;
    }

    public void setParams(Map<String, String[]> params) {
        this.params = params;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public RequestConfig getConfig() {
        return config;
    }

    public void setConfig(RequestConfig config) {
        this.config = config;
    }
}
